version 8.2
capture clear
capture log close
set more off
set mem 1000m
set mat 800
set scheme s2mono

use "GDP per capita_clean2.dta", replace
keep if year==2015
keep  countryname gdppppconstant2011internationaln log_gdppercapita2 countrycode
sort countryname
save "GDP per capita_clean_2015.dta", replace

use "Cost of claim.dta"

replace economy="Bangladesh" if economy=="Bangladesh - Dhaka"
replace economy="Brazil" if economy=="Brazil - Rio de Janeiro"
replace economy="China" if economy=="China - Beijing"
replace economy="India" if economy=="India - Delhi"
replace economy="Indonesia" if economy=="Indonesia - Jakarta"
replace economy="Japan" if economy=="Japan - Tokyo"
replace economy="Mexico" if economy=="Mexico - Mexico City"
replace economy="Nigeria" if economy=="Nigeria - Lagos"
replace economy="Pakistan" if economy=="Pakistan - Karachi"
replace economy="Russian Federation" if economy=="Russian Federation - Moscow"
replace economy="United States" if economy=="United States - New York City"

sort economy

save "Cost of claim.dta", replace

use "Doing business_Enforcing contracts.dta"

keep if year=="DB2016"

sort economy
merge economy using "Cost of claim.dta"
drop _merge


gen p=enforcingcontractsqualityofjudic/18
gen T=enforcingcontractstimedays/365
gen L_claim=enforcingcontractscostofclaim/100

gen L_claim2=(courtfees+enforcementfees)/100

local beta=0.95

**Using the formula of each-party-pays:
gen sueing_condition=p*(`beta')^T-L_claim
gen no_renegotiation_condition=p*(`beta')^T+L_claim-1 if sueing_condition>=0 
*Note: there is no point calculating the renegotiation_condition if the sueing_condition does not hold
*since in this case, there is no sueing, thus complete renegotiation

/*We take this out for now, since it is not clear if Kenya is on a loser-pays-all system
***Only the US has each-party-pays ,other countries use loser-pays-all:
replace sueing_condition=p*(`beta')^T-(1-p)*2*L_claim  if economy!="United States"
replace no_renegotiation_condition=p*(`beta')^T+p*2*L_claim-1 if sueing_condition>=0 & economy!="United States"
*/



sort sueing_condition
*browse economy sueing_condition no_renegotiation_condition

sort no_renegotiation_condition
browse economy sueing_condition no_renegotiation_condition

browse economy  p T L_claim sueing_condition no_renegotiation_condition if economy=="Kazakhstan"|economy=="China"|economy=="Russian Federation"|economy=="Liberia"|economy=="Kenya"|economy=="France"|economy=="Canada"|economy=="United States"


****Very nice graphs of World Bank:
*worldstat World, stat(GDP)
*worldstat World, stat(RL.EST)
*worldstat World, stat(UPP.COM.POL.XQ)
*http://worldbank.270a.info/classification/indicator/UPP.COM.POL.XQ.html

***Harmonize the name of countries with World Development Indicators:
replace economy="Congo, Dem. Rep." if economy=="Congo, Dem Rep"
replace economy="Congo, Rep." if economy=="Congo, Rep"
replace economy="Cote d'Ivoire" if economy=="Cote d�Ivoire"
replace economy="Egypt, Arab Rep." if economy=="Egypt, Arab Rep"
replace economy="Iran, Islamic Rep." if economy=="Iran, Islamic Rep"
replace economy="Korea, Rep." if economy=="Korea, Rep"
replace economy="Micronesia, Fed. Sts." if economy=="Micronesia, Fed Sts"
replace economy="St. Kitts and Nevis" if economy=="St Kitts and Nevis"
replace economy="St. Vincent and the Grenadines" if economy=="St Vincent and the Grenadines"
replace economy="St. Lucia" if economy=="St Lucia"
replace economy="Sao Tome and Principe" if economy=="S�o Tom� and Pr�ncipe"
replace economy="Yemen, Rep." if economy=="Yemen, Rep"

keep economy sueing_condition no_renegotiation_condition
ren economy countryname
sort countryname
save "Doing business_p_betaT_l.dta", replace


merge 1:1 countryname using "GDP per capita_clean_2015.dta"
sort countryname

drop if countryname=="Timor-Leste"


reg log_gdppercapita2 sueing_condition

graph twoway (scatter log_gdppercapita2 sueing_condition, mlabel(countrycode) mlabposition(0) msymbol(i)  mlabsize(1.5)) (lfit log_gdppercapita2 sueing_condition)

*KMH: cambodia and IDN: Indonesia a bit outliers


ren countryname NAME 
keep NAME sueing_condition no_renegotiation_condition gdppppconstant2011internationaln
sort NAME
save "Doing business_Enforcing contracts_clean.dta", replace

***Map:

*Map from: http://thematicmapping.org/downloads/world_borders.php

shp2dta using "TM_WORLD_BORDERS-0.3.shp", database(worlddb) coordinates(worldcoord) genid(id) replace


clear
use "worlddb"

****Harmonize name of countries:
replace NAME="Bahamas, The" if NAME=="Bahamas"
replace NAME="Cabo Verde" if NAME=="Cape Verde"
replace NAME="Congo, Dem. Rep." if NAME=="Democratic Republic of the Congo"
replace NAME="Congo, Rep." if NAME=="Congo"
replace NAME="Egypt, Arab Rep." if NAME=="Egypt"
replace NAME="Gambia, The" if NAME=="Gambia"
replace NAME="Hong Kong" if NAME=="Hong Kong SAR, China"
replace NAME="Iran, Islamic Rep." if NAME=="Iran (Islamic Republic of)"
replace NAME="Korea, Dem. People�s Rep." if NAME=="Korea, Democratic People's Republic of"
replace NAME="Korea, Rep." if NAME=="Korea, Republic of"
replace NAME="Kyrgyz Republic" if NAME=="Kyrgyzstan"
replace NAME="Lao PDR" if NAME=="Lao People's Democratic Republic"
replace NAME="Libya" if NAME=="Libyan Arab Jamahiriya"
replace NAME="Macao SAR, China" if NAME=="Macau"
replace NAME="Micronesia, Fed. Sts." if NAME=="Micronesia, Federated States of"
replace NAME="Myanmar" if NAME=="Burma"
replace NAME="Russian Federation" if NAME=="Russia"
replace NAME="Slovak Republic" if NAME=="Slovakia"
replace NAME="St. Kitts and Nevis" if NAME=="Saint Kitts and Nevis"
replace NAME="St. Lucia" if NAME=="Saint Lucia"
replace NAME="St. Martin (French part)" if NAME=="Saint Martin"
replace NAME="St. Vincent and the Grenadines" if NAME=="Saint Vincent and the Grenadines"
replace NAME="Taiwan, China" if NAME=="Taiwan"
replace NAME="Macedonia, FYR" if NAME=="The former Yugoslav Republic of Macedonia"
replace NAME="Tanzania" if NAME=="United Republic of Tanzania"
replace NAME="Venezuela, RB" if NAME=="Venezuela"
replace NAME="Vietnam" if NAME=="Viet Nam"
replace NAME="West Bank and Gaza" if NAME=="Palestine"
replace NAME="Yemen, Rep." if NAME=="Yemen"
replace NAME="Moldova" if NAME=="Republic of Moldova"

sort NAME
merge 1:1 NAME using "Doing business_Enforcing contracts_clean.dta"

sort NAME
*browse NAME _merge sueing_condition

*spmap sueing_condition using "worldcoord", id(id) clmethod(custom) clbreaks(-1.5 -1 -0.5 0 0.5 1 1.5) fcolor(RdYlGn)
*In color:
spmap sueing_condition using "worldcoord", id(id) clmethod(custom) clbreaks(-1.5 -0.2 0 0.2 1.5) fcolor(RdYlGn)
graph export "Map World Sueing Condition.png", replace

*In black and white:
spmap sueing_condition using "worldcoord", id(id) clmethod(custom) clbreaks(-1.5 -0.2 0 0.2 1.5) fcolor(Greys)
graph export "Figure 2 Map World Sueing Condition in black and white.png", replace


graph export "Map World Sueing Condition.png", replace

spmap no_renegotiation_condition using "worldcoord", id(id) clmethod(custom) clbreaks(-1.5 -0.2 0 0.2 1.5) fcolor(RdYlGn)
graph export "Map World No renegotiation Condition.png", replace

